#include  "c11_T7_complex.h"
#include <iostream>

/*Complex::Complex()
{
	real = 0.0;
	imag = 0.0;
}*/

Complex::Complex(double r, double i)
{
	real = r;
	imag = i;
}

Complex Complex::operator + (const Complex & c) const
{
	Complex sum;
	sum.real = real + c.real;
	sum.imag = imag + c.imag;
	return sum;
}

Complex Complex::operator - (const Complex & c) const
{
	Complex diff;
	diff.real = real - c.real;
	diff.imag = imag - c.imag;
	return diff;
}

Complex Complex::operator * (const Complex & c) const
{
	Complex mult;
	mult.real = (real * c.real - imag * c.imag);
	mult.imag = (real * c.imag + imag * c.real);
	return mult;
}

Complex Complex::operator * (double d) const
{
	return Complex(d*real, d*imag);
}

std::ostream & operator << (std::ostream & os, const Complex & c)
{
	os << "(" << c.real << "," << c.imag << "i)";
	return os;
}

bool operator >> (std::istream & is, Complex & c)
{
	Complex inputBuffer;

	if ((std::cout << "real: ") && !(is >> inputBuffer.real))
	{
		std::cout << "End\n";
		return false;
	}
	else if ((std::cout << "imaginary: ") && !(is >> inputBuffer.imag))
	{
		std::cout << "End\n";
		return false;
	}

	c.real = inputBuffer.real;
	c.imag = inputBuffer.imag;
	return true;
}

Complex::~Complex()
{
}
